import { request } from '@/utils/request.js';

// 微信登录获取SesionId
export const getSessionId = (code) => {
    return request({
        url: '/third/wechat/getSessionId',
        data: {
            platform: 'miniProgram',
            payload: encodeURIComponent(JSON.stringify({ code, auto_login: false }))
        }
    });
};
// 微信登录
export const wechatLogin = (sessionId,invite_code) => {
    return request({
        url: '/third/wechat/login',
        data: {
            platform: 'miniProgram',
            payload: encodeURIComponent(JSON.stringify({ sessionId })),
			invite_code:invite_code
        }
    });
};
// 绑定手机号
export const bindPhone = (sessionId, iv, encryptedData, token) => {
    return request({
        url: '/third/wechat/bindUserPhoneNumber',
        data: {
            platform: 'miniProgram',
            payload: encodeURIComponent(JSON.stringify({ sessionId, iv, encryptedData }))
        },
        header: { token: token }
    });
};
//账号密码登录
export const loginIndex = (data) => {
    return request({
        url: '/user/login',
        isJson: true,
        data: data
    });
};
// 用户信息
export const user = () => {
    return request({
        url: '/user/info'
    });
};
// 我的邀请
export const inviteList = () => {
    return request({
        url: '/user/inviteList'
    });
};
// 获取首页分类
export const category = (pid = 0) => {
    return request({
        url: `/category/index?pid=${pid}`
    });
};
// 关于我们
export const richtext = (id = 3) => {
    return request({
        url: '/richtext/index',
        data: {
            id: id
        }
    });
};
//商铺列表
export const shops = (data) => {
    return request({
        url: `/index/shop?page=${data.page}&lat=${data.lat}&lng=${data.lng}`,
        isJson: false,
        // data: data
    });
};
//申请入驻
export const apply = (data) => {
    return request({
        url: '/shop/shop/apply',
        isJson: true,
        data: data
    });
};

//商铺商品列表
export const shopGoods = (data) => {
    return request({
        url: `/shop/goods/index?status=${data.status}&order=${data.order}&sort=${data.sort}&page=${data.page}`,
        isJson: false
    });
};
//商品上架/下架
export const orderUp = (id) => {
    return request({
        url: '/shop/goods/operation',
        isJson: true,
        data: {
            goods_id: id
        }
    });
};
//获取商品分类
export const goodsCategory = () => {
    return request({
        url: '/shop/goods_category/index',
        isJson: true
    });
};
//退出登录
export const logout = () => {
    return request({
        url: '/user/logout',
        isJson: true
    });
};
//我的订单
export const getOrder = (type, page) => {
    return request({
        url: '/order/index',
        isJson: true,
        data: {
            type: type,
            page: page
        }
    });
};
//订单详情
export const getOrderDetails = (id) => {
    return request({
        url: '/order/detail',
        isJson: true,
        data: {
            id: id
        }
    });
};
//取消订单
export const cancelOrder = (id) => {
    return request({
        url: '/order/cancel',
        isJson: true,
        data: {
            id: id
        }
    });
};
//购物车列表
export const carList = () => {
    return request({
        url: '/cart/index',
        isJson: true
    });
};
//更新购物车 类型：inc=增加,dec=减少,cover=覆盖
export const carUPdate = (goods_id, goods_num, type = 'cover', goods_sku_price_id) => {
    return request({
        url: '/cart/update',
        data: {
            goods_id: goods_id,
            goods_num: goods_num,
            type: type,
            goods_sku_price_id: goods_sku_price_id
        },
        isJson: true
    });
};
//订单核销
export const verified = (id) => {
    return request({
        url: '/shop/order/verified',
        isJson: true,
        data: {
            order_sn: id
        }
    });
};
// 删除订单
export const delOrder = (id) => {
    return request({
        url: '/order/delete',
        isJson: true,
        data: {
            id: id
        }
    });
};
// 首页轮播图 lng经度,lat纬度
export const oneIndex = (lng, lat) => {
    return request({
        url: `/index/index?lng=${lng}&lat=${lat}`,
        method: 'GET',
        isJson: true
    });
};
//上传/编辑商品
export const addGoods = (data) => {
    return request({
        url: '/shop/goods/edit',
        isJson: true,
        data: data
    });
};
// 获取店铺商品详情
export const goodsDetail = (id) => {
    return request({
        url: `/shop/goods/detail?ids=${id}`,
        method: 'GET',
        isJson: true
    });
};
// 获取商品详情
export const goodsxq = (id) => {
    return request({
        url: `/goods/detail?ids=${id}`,
        method: 'GET',
        isJson: true
    });
};
// 用户看的店铺信息和左侧侧边栏
export const goodstore = (id) => {
    return request({
        url: `/store/index?shop_id=${id}`,
        method: 'GET',
        isJson: true
    });
};
// 右边的内容
export const getGoodsList = (shop_id, category_id) => {
    return request({
        url: `/store/getGoodsList?shop_id=${shop_id}&category_id=${category_id}`,
        method: 'GET',
        isJson: true
    });
};
//创建订单数据
export const getCreate = (data) => {
    return request({
        url: '/order/create',
        isJson: true,
        data: data
    });
};
//支付
export const getWechat = (data) => {
    return request({
        url: '/pay/prepay',
        isJson: true,
        data: data,
        header: { platform: 'WechatMiniProgram' }
    });
};
// 获取分类里内容
export const getClass = (id, page) => {
    return request({
        url: `/goods/index?category_id=${id}&page=${page}&limit=10`
    });
};
// 商铺后台
export const getshopbk = () => {
    return request({
        url: '/shop/shop/index'
    });
};
//保存银行卡账号信息
export const accountSave = (data) => {
    return request({
        url: '/account/save',
        isJson: true,
        data: data
    });
};
// 获取银行卡账号信息
export const getBank = (type = 'bank') => {
    return request({
        url: `/account/index?type=${type}`,
        method: 'GET',
        isJson: true
    });
};
//商务入驻
export const agent = (data) => {
    return request({
        url: '/agent/apply',
        isJson: true,
        data: data
    });
};
//修改支付密码
export const updatePayPassword = (data) => {
    return request({
        url: '/user/updatePayPassword',
        isJson: true,
        data: data
    });
};
//删除购物车
export const delCar = (id) => {
    return request({
        url: '/cart/delete',
        isJson: true,
        data: {
            ids: id
        }
    });
};
// 搜索商品
export const searchGood = (keywords, page, limit) => {
    return request({
        url: `/goods/search?keywords=${keywords}&page=${page}&limit=10`,
        method: 'GET',
        isJson: true
    });
};
// 分类拖拽排序
export const goodsWeigh = (ids, changeid) => {
    return request({
        url: '/shop/goods_category/weigh',
        isJson: true,
        data: {
            ids: ids,
            changeid: changeid
        }
    });
};
// 删除商品分类
export const delFl = (id) => {
    return request({
        url: '/shop/goods_category/del',
        isJson: true,
        data: {
            ids: id
        }
    });
};
// 添加商品分类
export const addSp = (data) => {
    return request({
        url: '/shop/goods_category/edit',
        isJson: true,
        data: data
    });
};
//商务后台数据
export const agentht = () => {
    return request({
        url: '/agent/index',
        isJson: true
    });
};
//商务后台数据
export const getQrcode = (data) => {
    return request({
        url: `/bullbat/qrcode?text=${data}`,
        isJson: false
    });
};
//抵用券获取列表
export const getVoucherList = (data) => {
    return request({
        url: `/voucher/getList?page=${data.page}&limit=${data.limit}&query_time=${data.query_time}`,
        isJson: false,
		method: 'GET',
    });
};
//抵用券激活记录
export const getVoucherActivateList = (data) => {
    return request({
        url: `/voucher/activateList?page=${data.page}&limit=${data.limit}&query_time=${data.query_time}`,
        isJson: false,
		method: 'GET',
    });
};

//抵用券使用记录
export const getvoucherUseLog = (data) => {
    return request({
        url: `/voucher/useLog?page=${data.page}&limit=${data.limit}&query_time=${data.query_time}`,
        isJson: false,
		method: 'GET',
    });
};

//积分激活
export const quanjihuo = (data) => {
    return request({
        url: `/voucher/activate`,
        isJson: true,
		data:{
			amount:data.amount
		},
    });
};

//商家提现
export const withdrawApply = (data) => {
    return request({
        url: `/shop/withdraw/apply`,
        isJson: true,
		data:data
    });
};

//二维码
export const shopqrcode = (data) => {
    return request({
        url: `/shop/shop/qrcode`,
           isJson: false,
    });
};
//商家订单数据
export const shopOrderIndex = (data) => {
    return request({
        url: `/shop/order/index?page=${data.page}`,
	   isJson: false,
	   method: 'GET',
    });
};
//商家月数据
export const shopTurnover = (data) => {
    return request({
        url: `/shop/shop/turnover?page=${data.page}&limit=${data.limit}&query_time=${data.query_time}`,
        isJson: false,
		method: 'GET',
    });
};
//获取商务店铺数量
export const shopNum = (data) => {
    return request({
        url: `/agent/getShopList`,
           isJson: false,
    });
};
//获取商务业绩（月份）
export const getProfit = (data) => {
    return request({
        url: `/agent/getProfit?month=${data}`,
	   isJson: false,
    });
};
export const getShopOrderList = (data) => {
    return request({
        url: `/agent/getShopOrderList?shop_id=${data}`,
	   isJson: false,
    });
};
export const getQr = (data) => {
    return request({
        url: `/index/qrcode`,
	   isJson: false,
    });
};
export const scanCreateOrder = (data) => {
    return request({
        url: `/order/scanCreateOrder`,
		data:data,
		isJson: true,
    });
};